package com.zhouxiaoge.controller;

import com.zhouxiaoge.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.LinkedHashMap;
import java.util.List;

/**
 * @author 周明阳
 * mail:gqzmy@outlook.com
 * 时间:2018-03-20 16:45
 */
@RestController
public class MovieController {

    private final RestTemplate restTemplate;
    @Value("${user.userServicePath}")
    private String userServicePath;

    @Autowired
    public MovieController(RestTemplate restTemplate) {
        this.restTemplate = restTemplate;
    }

    @GetMapping("/movie/{id}")
    public ResponseEntity<User> findById(@PathVariable Long id) {
        return this.restTemplate.getForEntity(userServicePath + "/simple/" + id, User.class);
    }

    @GetMapping("/movies")
    public void queryAll() {
        List forObject = this.restTemplate.getForObject(userServicePath + "/simple/list", List.class);
        for (Object o : forObject) {
            LinkedHashMap hashMap = (LinkedHashMap) o;
            Object id = hashMap.get("id");
            System.out.println(id.toString());
            System.out.println(o.toString());
        }
    }
}
